#include "ggpvision.h"
/*--------------------------------------------------------------------------------*/
REAL
	Angle = 0;
GRAPHIC_TEXTURE::REF
	Tex = NULL,
	Tex2 = NULL;
GRAPHIC_TEXTURE_SET::REF
	ExplosionSet;
GRAPHIC_2D_QUAD
	quad;
GRAPHIC_FONT::REF
	Font = NULL;
GRAPHIC_TEXT
	Text;
GRAPHIC_TEXT_FPS
	FpsText;
/*--------------------------------------------------------------------------------*/
VOID StupidRender()
{
	OPENGL_Color( COLOR::ColorWhite );
	OPENGL_PushMatrix();
	{

		OPENGL_RotateZ( Angle );
		GRAPHIC_2D_RENDERER::GetInstance().RenderObject( GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 256, 256 ) ), Tex );

		OPENGL_RotateZ( -Angle * 2 );
		GRAPHIC_2D_RENDERER::GetInstance().RenderObject( GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 256, 256 ) ), Tex2 );

		OPENGL_RotateZ( Angle * 3 );
		GRAPHIC_2D_RENDERER::GetInstance().RenderObject( quad, TexSet );
		Text.Render();

		OPENGL_Color( COLOR::ColorWhite );

		OPENGL_PushMatrix();
		{
			OPENGL_TranslateX( 250.0f );
			OPENGL_RotateZ( Angle * 5 );
			GRAPHIC_2D_RENDERER::GetInstance().RenderObject( quad, TexSet );
			GRAPHIC_2D_RENDERER::GetInstance().RenderObject( GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 128, 128 ) ), Tex );
		}
		OPENGL_PopMatrix();


		OPENGL_PushMatrix();
		{
			OPENGL_TranslateX( -250.0f );
			OPENGL_RotateZ( -Angle * 5 );
			GRAPHIC_2D_RENDERER::GetInstance().RenderObject( quad, TexSet );
			GRAPHIC_2D_RENDERER::GetInstance().RenderObject( GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 128, 128 ) ), Tex );
		}
		OPENGL_PopMatrix();
	}
    OPENGL_PopMatrix();
}
/*--------------------------------------------------------------------------------*/
VOID Render()
{
    FpsText.Render();
    Text.Render();

	GRAPHIC_2D_RENDERER::GetInstance().RenderObject( GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 128, 128 ) ), ExplosionSet );
}
/*--------------------------------------------------------------------------------*/
VOID Update( const TIMER & time_step )
{
     Angle += 35 * time_step.GetSecondCount();
     FpsText.Update( time_step );

     INPUT_SYSTEM::GetInstance().Update( time_step );

     if( INPUT_SYSTEM::GetInstance().IsKeyJustReleased( INPUT_KEY_Escape ) )
     {
    	 APPLICATION_Quit();
     }
}
/*--------------------------------------------------------------------------------*/
INT main()
{
	
    APPLICATION::CreateInstance();
    GRAPHIC_2D_RENDERER::CreateInstance();   
    GRAPHIC_EXTENSION_MANAGER::CreateInstance();
    INPUT_FILE_MANAGER::CreateInstance();
    INPUT_SYSTEM::CreateInstance();
	
    APPLICATION_SetName( "ggpvision demo application" );
    APPLICATION_SetExtent( 800, 600 );
    APPLICATION_SetRenderCallBack( &Render );
    APPLICATION_SetUpdateCallBack( &Update );
    APPLICATION_Initialize( false );
        
    GRAPHIC_EXTENSION_MANAGER::GetInstance().Initialize();

	INPUT_FILE_MANAGER_MountDirectory( "./data" );

    Tex2 = GRAPHIC_TEXTURE::CreateTextureFromFile( "font2" );
	Tex = GRAPHIC_TEXTURE::CreateTextureFromFile( "texture" );
	TexSet = GRAPHIC_TEXTURE_SET::CreateTextureSetFromFile( "font2", 16, 16 );

	ExplosionSet = GRAPHIC_TEXTURE_SET::CreateTextureSetFromFile( "bomba", 5, 5 );

	quad = GRAPHIC_2D_QUAD( MATH_VECTOR_2( 0, 0 ), MATH_VECTOR_2( 256, 256 ) );
	quad.SetUVCoord( TexSet->GetUVCoord( 'G' ) );

	Font = GRAPHIC_FONT::CreateFromFile( "font2", "Default" );
	Text.SetFont( Font );
	Text.SetExtent( MATH_VECTOR_2( 380.0f, 64.0f ) );
	Text.SetPosition( MATH_VECTOR_2( 0, 0 ) );
	Text.SetText( "ggpvision-0.10" );
	Text.SetColor( COLOR::ColorYellow );

	Text.Update();

	FpsText.SetPosition( MATH_VECTOR_2( 330.0f, 280.0f ) );
	FpsText.SetExtent( MATH_VECTOR_2( 140.0f, 16.0f ) );
	FpsText.SetFont( Font );
	FpsText.SetColor( COLOR::ColorGreen );

	INPUT_SYSTEM::GetInstance().Initialize();

    APPLICATION_Start();

    return 0;
}
